home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: How big is the 0
- Date: 19 Feb 1996 20:30:59 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4gamm3$4q7@dawn.mmm.com>
- References: <1996Feb17.132420.114207@kuhub.cc.ukans.edu>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- anh@kuhub.cc.ukans.edu wrote:
-
- > Hello,
-
- > In C, anytime I need to do a null pointer check I would do this:
-
- > MyType *p;
-
- > if(p==(MyType*)0)
- > bla;
-
- The cast is not necessary.
-
- > The new operator supposedly return a 0 upon failure.
-
- Not any more. It is guaranteed to never return 0. It will either return
- a valid pointer or throw an exception.
-
- Of course, if you have an older compiler, all bets are off :-)
-
- > Can I rely on the
- > compiler to make sure the 0 is as big as the size of the pointer? For
- > example, ALPHA's pointers are 64 bits long which is different from the 32 bits
- > int.
-
- Comparing any pointer to a literal 0 will work just fine.
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-